package diutils

import (
	"gitee.com/ichub/goconfig/common/base/basedto"
	"gitee.com/ichub/goconfig/common/base/baseutils/fileutils"
	"gitee.com/ichub/goconfig/common/ichubconfig"
)

func FindKey(key string) bool {
	return FindBeanDiUtils().FindKey(key)
}

const ini_key = "di"
const di_define_file = "/config/di/di_define.ini"

type DiUtils struct {
	basedto.BaseEntitySingle

	rootdir string
	ini     *ichubconfig.IchubConfigIni `json:"-"`
	//key struct ->bool
	Items map[string]string
}

func NewDiUtils() *DiUtils {
	var u = &DiUtils{
		rootdir: fileutils.FindRootDir(),
		ini:     ichubconfig.NewIchubConfigIni(),
	}
	u.init()
	return u
}

func (u *DiUtils) init() {
	u.LoadConfig()
}

func (this *DiUtils) FindKey(key string) bool {
	b, ok := this.Items[key]
	return b == "true" || ok
}

func (this *DiUtils) LoadConfig() {
	this.ini.Load(this.rootdir + "/" + di_define_file)
	this.Items = this.ini.FindMap(ini_key)
}
